package com.ecfront.test.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.ecfront.dao.MessageDAO;
import com.ecfront.pojo.GoodsImpl;
import com.ecfront.pojo.Message;
import com.ecfront.pojo.Shop;
import com.ecfront.pojo.User;
import junit.framework.TestCase;

public class testMessage extends TestCase {
	private static final MessageDAO messageDao = (MessageDAO)SpringUtilTest.getBean("MessageDAO");
	//save or update test
	public void testSaveOrUpdate(){
		Message message = new Message();
		//message.setId(1);
		message.setContent("你好！！我知道你这件货还有存活没？");
		message.setDate(new Date());
		message.setType(1);
		
		User user = new User();
		user.setId(1);
		message.setUser(user);
		
		Shop shop = new Shop();
		shop.setId(1);
		message.setShop(shop);
			
		messageDao.save(message);
	}
	//findAll test
	public void testFindAll(){
		List list = messageDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			Message message = (Message)iter.next();
			System.out.println(message.getContent());
			
			System.out.println(message.getGoodssub().getGood().getName());
			System.out.println(message.getUser().getName());
			System.out.println(message.getShop().getName());
		}
	}
	//delete test
	public void testDel(){
		Message message = new Message();
		message.setId(2);
		
		messageDao.delete(message);
	}
	//findById test
	public void testFindById(){
		Message message = messageDao.findById(1);
		System.out.println(message.getContent());
		
		System.out.println(message.getGoodssub().getGood().getName());
		System.out.println(message.getUser().getName());
		System.out.println(message.getShop().getName());
	}
	//property test
	public void testProperty(){
		List list = messageDao.findByMtype(0);
		for(Iterator iter = list.iterator();iter.hasNext();){
			Message message = (Message)iter.next();
			System.out.println(message.getContent());
			
			//System.out.println(message.getGoodssub().getGood().getName());
			System.out.println(message.getUser().getName());
			System.out.println(message.getShop().getName());
		}
	}
}
